<?php

include_once 'Super_Model.php';

class Application_Model_ShortStories extends Super_Model {

    private $aCategories = array(
        1 => 'Php',
        5 => 'Zend',
        10 => 'Базы данных',
        20 => 'JavaScript',
        30 => 'HTML',
        50 => 'Unix',
        60 => 'Регулярные выражения',
        70 => 'Алгоритмы',
        1000 => 'Разное'
    );
    private $aShortStoriesCategories = array(
        1 => array('id' => 1, 'title' => 'Твиты', 'url' => 'tweet',),
        2 => array('id' => 2, 'title' => 'Заметки на полях', 'url' => 'note', 'is_group_cat' => TRUE),
        3 => array('id' => 3, 'title' => 'Учу английский', 'url' => 'english'),
        4 => array('id' => 4, 'title' => 'Рефакторинг', 'url' => 'martin_fowlers_refactoring'),
        5 => array('id' => 5, 'title' => 'Юмор', 'url' => 'humor'),
    );

    public function getShortStoriesTypes() {
        return $this->aShortStoriesCategories;
    }

    public function getShortStoriesCat() {
        return $this->aCategories;
    }

    public function getShortStoriesCategoriesIDByUrl($url) {
        foreach ($this->aShortStoriesCategories as $aStoriesCat) {
            if (!empty($aStoriesCat['url']) && $aStoriesCat['url'] == $url)
                return $aStoriesCat['id'];
        }
        return FALSE;
    }

    public function getShortStoriesByType($sType) {
        $iShortStoryCatID = $this->getShortStoriesCategoriesIDByUrl($sType);
        if ($iShortStoryCatID)
            return $this->select('short_stories', '*', '`active`=1 AND `type`=' . $iShortStoryCatID, '`public_date` DESC, `id` DESC');
        return FALSE;
    }
    
    public function getShortStoriesTitleByType($sType, $iLimit) {
        $iShortStoryCatID = $this->getShortStoriesCategoriesIDByUrl($sType);
        if ($iShortStoryCatID)
            return $this->select('short_stories', '`title`', '`active`=1 AND `type`=' . $iShortStoryCatID, '`public_date` DESC, `id` DESC', $iLimit);
        return FALSE;
    }

}